#coding:utf-8
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import  receiver

# Create your models here.
class Onetoone(models.Model):
    user = models.OneToOneField(User,on_delete= models.CASCADE) #一对一的扩展auth_user
    resume = models.TextField(max_length=500,blank=True) # 字段扩展 介绍
    location = models.CharField(max_length=30,blank=True)
    birth_date = models.DateField(null=True,blank=True) #出生日期


@receiver(post_save,sender=User)
def create_user_profile(sender,instance,created,**Kwargs):
    if created:
        Onetoone.objects.create(user = instance)


@receiver(post_save,sender = User)
def save_user_profile(sender,instance,**kwargs):
    instance.onetoone.save()

